package com.lt.utils.String;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author LiuTong
 */
public class FontUtils {

    private static List<Typeface> typefaces = new ArrayList<>();
    private static Set<String> paths = new HashSet<>();
    static {
        paths.add("fonts/daLiang.ttf");
        paths.add("fonts/hanTi.ttf");
        paths.add("fonts/jinTi.ttf");
        paths.add("fonts/heiTi.ttf");
        paths.add("fonts/weiRuanTi.ttf");
    }
    public static void addFontTypeface(String path){
        paths.add(path);
    }

    public static Set<String> getPaths(){
        return paths;
    }

    public static void init(Context context){
        if(typefaces == null || typefaces.size() <=0){
            AssetManager assetManager = context.getResources().getAssets();
            for(String path : paths){
                try {
                    Typeface typeface = Typeface.createFromAsset(assetManager,path);
                    typefaces.add(typeface);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
    public static List<Typeface> getTypefaces(){
        if (typefaces != null && typefaces.size() > 0) {
            return typefaces;
        }
        List<Typeface> defaultList = new ArrayList<>();
        defaultList.add(Typeface.DEFAULT);
        return defaultList;
    }
}
